using System;
using System.Collections.Generic;

namespace Windy.Transformations
{
    public class CachedTransformSink<TInput, TOutput> : CachedTransformSinkBase<TInput, TOutput, CachedTransformSink<TInput, TOutput>>
    {
        public CachedTransformSink(
            Action<int, TInput> voidTransformSink = null,
            Action<int, TInput, TOutput> monoTransformSink = null,
            Action<int, TInput, IEnumerable<TOutput>, Action<Action>> varyTransformSink = null,
            Action transformBeginHandler = null,
            Action transformCompleteHandler = null,
            Action transformAbortHandler = null)
        {
            Initialize(
              voidTransformSink,
              monoTransformSink,
              varyTransformSink,
              transformBeginHandler,
              transformCompleteHandler,
              transformAbortHandler);
        }

        public Queue<Action> Actions;

        protected override void RecordAction(Action action)
        {
            Actions.Enqueue(action);
        }
        protected override void BeginRecordActions()
        {
            Actions = new Queue<Action>();
        }
        protected override void AbandonActions()
        {
            Actions = null;
        }
        protected override void ApplyActions()
        {
            while (Actions.Count > 0)
                Actions.Dequeue()();
        }
    }
}
